/** 
 * @Company: 北京慧点科技有限公司 | www.smartdot.com.cn
 * @Copyright 1998-2022 © Smartdot Technologies Co., Ltd.
 */
package com.hd.rcugrc.project.leaveapplication.leave.service.impl;

import com.hd.rcugrc.bpm.facade.mobile.mvc.query.ListQueryResult;
import com.hd.rcugrc.project.leaveapplication.leave.dao.OaOfficeLeaveDao;
import com.hd.rcugrc.project.leaveapplication.leave.entity.OaOfficeLeaveEntity;
import com.hd.rcugrc.project.leaveapplication.leave.service.OaOfficeLeaveService;
import com.hd.rcugrc.security.user.User;
import com.hd.rcugrc.security.user.UserInfoService;
import com.hd.wep.extend.common.enums.EndTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hd.wep.extend.common.service.impl.WeFlowBaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;


/**
 * 请假申请单 - Service实现类 - 由代码生成器生成
 * 
 * @class: OaOfficeLeaveServiceImpl
 * @date 2024-07-15 09:35:47
 * @author smartdot
 * @version 1.0 - 2024-07-15 09:35:47
 * @see
 */
public class OaOfficeLeaveServiceImpl extends WeFlowBaseServiceImpl<OaOfficeLeaveDao, OaOfficeLeaveEntity>
        implements OaOfficeLeaveService {
    
    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    OaOfficeLeaveDao oaOfficeLeaveDao;

    @Autowired
    public UserInfoService userInfoService;
    @Override
    public String getLevelByAccount(String account) {
        User user = userInfoService.getUserByAccount(account);
        return user.getName();
    }

    @Override
    public String getInitiatingDepartment(String account) {
        User user = userInfoService.getUserByAccount(account);
        return userInfoService.getGroupById(user.getParentId()).getName();
    }

    @Override
    public Long getCreationTime() {
        return System.currentTimeMillis();
    }

    @Override
    public String getSerialNumber() {
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String string = date.format(formatter);
        return string + "520";
    }

    @Override
    public String getTitle() {
        return "请假申请";
    }

    @Override
    public ListQueryResult getProcessedData() {
        return getReturnedValue(1);
    }

    @Override
    public ListQueryResult getArleadyProcessed() {
        return getReturnedValue(3);
    }

    @Override
    public ListQueryResult getClosedAccount(){
        return getReturnedValue(5);
    }

    public ListQueryResult getReturnedValue(int k) {
        ListQueryResult listQueryResult = new ListQueryResult();
        List<OaOfficeLeaveEntity> list = oaOfficeLeaveDao.findAll();
        List<OaOfficeLeaveEntity>  leaveEntities = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            OaOfficeLeaveEntity oaOfficeLeaveEntity = list.get(i);
            if(oaOfficeLeaveEntity.getEndType() == k) {
                leaveEntities.add(oaOfficeLeaveEntity);
            }
        }
        listQueryResult.setData(leaveEntities.toArray());
        listQueryResult.setTotalSize(leaveEntities.size());
        return listQueryResult;
    }
//    // 年假维护
//    public OaOfficeLeaveEntity flowStatusChange(Long beanId, Integer endType, String flowState) {
//        OaOfficeLeaveEntity entity = this.getById(beanId);
//        if(entity.getEndType() == EndTypeEnum.DRAFT.getIndex() && endType == EndTypeEnum.ACTIVATED.getIndex()) {
//
//        }
//        return new OaOfficeLeaveEntity();
//    }
}
